{{- $page := . }}
{{- with index site.Menus.main }}
<nav id="navbar" class="navbar">
    <ul>
        {{- partial "partials/inline/menu/main/walk.html" (dict "page" $page "menuEntries" .) }}
    </ul>
    <i class="bi bi-list mobile-nav-toggle"></i>
</nav>
{{- end }}

{{- define "partials/inline/menu/main/walk.html" }}
{{- $page := .page }}
{{- range .menuEntries }}
{{- $active := eq ($page.RelPermalink | relLangURL) .URL }}
{{- $linkattrs := dict "href" .URL }}
{{- $liattrs := dict }}
{{- if .HasChildren}}
{{- $linkattrs = merge $linkattrs (dict "class" .Params.Class) }}
{{- $liattrs = merge $liattrs (dict "class" "dropdown") }}
{{- else if not .HasChildren }}
{{- if $active }}
{{- $linkclass := print .Params.Class " active"}}
{{- $linkattrs = merge $linkattrs (dict "class" $linkclass) }}
{{- else }}
{{- $linkattrs = merge $linkattrs (dict "class" .Params.Class) }}
{{- end }}
{{- end }}
<li {{- range $k, $v :=$liattrs }} {{- with $v }} {{- printf " %s=%q" $k $v | safeHTMLAttr }} {{- end }} {{- end -}}>
    <a {{- range $k, $v :=$linkattrs }} {{- with $v }} {{- printf " %s=%q" $k $v | safeHTMLAttr }} {{- end }} {{- end
        -}}>
    {{- if .HasChildren}}
        <span>{{ or (T .Identifier) .Name | safeHTML }}</span>
        <i class="bi bi-chevron-down"></i></a>
    {{- else }}
    {{ or (T .Identifier) .Name | safeHTML }}
    {{- end }}
    </a>
    {{- with .Children }}
    <ul>
        {{- partial "partials/inline/menu/main/walk.html" (dict "page" $page "menuEntries" .) }}
    </ul>
    {{- end }}
</li>
{{- end }}
{{- end }}
